<?php
namespace org\GoApi;
use Exception;

class UserCtrl {
  public static function Read($GameID) { // 读取
    $retn = [];
    try {
      $data = CallGameSrv('control/Read', ['GameID' => $GameID]);
      $data = json_decode($data, true);
      if (!empty($data['Data'][0])) {
        $retn = $data['Data'][0];
      }
    } catch (Exception $e) {
      //
    }
    return $retn;
  }
  public static function Remove($GameID) { // 删除
    $retn = false;
    try {
      $data = CallGameSrv('control/Delete', ['GameID' => $GameID]);
      $data = json_decode($data, true);
      $retn = $data['ErrorCode'];
    } catch (Exception $e) {
      //
    }
    return $retn; // 0=成功
  }
  public static function RemoveALL($channel) { // 删除全部
    $retn = false;
    try {
      $data = CallGameSrv('control/DeleteALL', ['channel' => $channel]);
      $data = json_decode($data, true);
      $retn = $data['ErrorCode'];
    } catch (Exception $e) {
      //
    }
    return $retn; // 0=成功
  }
  public static function Page($channel, $page = 1, $size = 20) { // 分页
    $page = $page > 0 ? $page : 1;
    $size = $size > 0 ? $size : 20;
    $retn = [];
    try {
      $data = CallGameSrv('control/Page', ['channel' => $channel, 'page' => $page, 'size' => $size]);
      $retn = json_decode($data, true);
    } catch (Exception $e) {
      //
    }
    return $retn;
  }
  public static function Save($GameID, $Range, $Rate, $NowSocre, $Channel) { // 添加/保存
    $retn = false;
    try {
      $data = CallGameSrv('control/Save', [
        'GameID'  => $GameID,
        'Range'   => $Range,
        'Rate'    => $Rate,
        'NowSocre'=> $NowSocre,
        'Channel' => $Channel,
      ]);
      $data = json_decode($data, true);
      $retn = $data['ErrorCode'];
    } catch (Exception $e) {
      //
    }
    return $retn;  // 0=成功
  }
}
